$(".el-input input").blur(function () {
    $(this).val(1);
});

$(".CartStyle").css({ visibility: "hidden" });

let vn = localStorage.getItem("vipName");
console.log(vn);

$(document).ready(function () {
    $.get("../rearEnd/goodsAndShoppingCart/getShoppingCart.php", "vipName=" + vn, function (data) {
        for (let i = 0; i < JSON.parse(data).length; i++) {
            $(".cartList").append(`<div class="listInfo">
            <label class="icon">
                <i class=""></i>
            </label>
            <div class="infoContent">
                <img src=${JSON.parse(data)[i].goodsImg}>
                <div class="info">
                    <span>OCX0${JSON.parse(data)[i].goodsId}</span>
                    <h5>${JSON.parse(data)[i].goodsName}</h5>
                    <div class="infoDescribe">
                        <p>
                            尺寸:
                            <span>${JSON.parse(data)[i].beiyong10 + "寸"}</span>
                        </p>
                        <p>
                            筛选色:
                            <span>${JSON.parse(data)[i].beiyong11}</span>
                        </p>
                        <div class="infoNum">
                            <span class="is_promote">${"￥" + JSON.parse(data)[i].goodsPrice}</span>
                            <span>x</span>
                            <select name="" id="" value="${JSON.parse(data)[i].goodsCount}">
                                
                            </select>   
                        </div>
                    </div>
                    <div class="operate">
                        <ul>
                            <li class="delete">删除</li>
                        </ul>
                        <div>${"￥" + JSON.parse(data)[i].goodsCount * JSON.parse(data)[i].goodsPrice}</div>
                    </div>
                </div>
            </div>
            </div>`);
            // $("select").val(JSON.parse(data)[i].goodsCount)
        }

        for (let i = 1; i < 99; i++) {
            let opt = $("<option>");
            opt.html(i)
            opt.appendTo($("select"));
        }

        for (let i = 0; i < JSON.parse(data).length; i++) {
            for (let j = 0; j < $("select option").length; j++) {
                $("select").eq(j).click(function () {
                    $(".operate div").eq(i).html("￥" + $("select").eq(i).eq(j).val() * JSON.parse(data)[i].goodsPrice);
                })
            }
        }
        console.log(JSON.parse(data));
        // console.log(JSON.parse(data)[0]);
        $(".CartStyle").css({ visibility: "visible" });
        if (data == "[]") {
            $(".cartNull").css({ display: "block" });
            $(".cartSelect").css({ display: "none" });
            $(".CartStyle").css({ display: "none" });
        } else {
            $("cartNull").css({ display: "none" });
        }
    });
})






$(".icon i").on("click", function () {
    $(this).toggleClass("Imgstatus");
    console.log(121212);
})


$(".cartList").on("click", ".icon i", function () {
    $(this).toggleClass("Imgstatus");

})


$(".cartList").on("click", ".delete", function () {
    let spId = $(this).parent().parent().parent().children("span").html();
    $(this).parent().parent().parent().parent().parent().remove();
    $.ajax({
        type: "GET",
        url: "../rearEnd/goodsAndShoppingCart/deleteGoods.php",
        data: {
            vipName: vn,
            goodsId: spId.substring(4, 7)
        },
        success: function (msg) {
            console.log(msg);
            if (msg == '1') {
                console.log("删除成功");

            } else {
                console.log("删除失败");
            }
        }
    });
});

$(".icon i").eq(0).on("click", function () {
    if ($(".icon i").attr("class") == "Imgstatus") {
        $(".icon i").attr("class", "");
    } else {
        $(".icon i").toggleClass("class", "Imgstatus");
    }

})

function tp() {
    for (let i = 0; i < $(".operate div").length; i++) {
        let totalPrice = 0;
        totalPrice += $(".operate div").html();
    }
}
